package com.wipz.eoa.iphone.alreadayDoTask;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.toft.widgets.workflow.factory.ServiceFactory;
import com.toft.widgets.workflow.factory.impl.ServiceFactoryImpl;
import com.toft.widgets.workflow.model.Page;
import com.toft.widgets.workflow.model.TaskItem;
import com.toft.widgets.workflow.provider.ApprocalAssistance;
import com.toft.widgets.workflow.utils.DateConvertUtil;

public class AlreadyDoTaskOperate {

	public List doQuery(String userCode) {
		TaskItem taskItem = new TaskItem();
		List list = new ArrayList();
		try {
			ApprocalAssistance.beginTransaction();
			Page page = new Page(200);
			List result = this.getServiceFactory().getWorkflowQueryService().findHistoryTasks(userCode, taskItem, page).getResult();
			if (!result.isEmpty() || result.size() != 0) {
				for (int i = 0; i < result.size(); i++) {
					TaskItem task = (TaskItem) result.get(i);
					Map map = new HashMap();
					//map.put("NOTENAME", task.getActivityName());
					map.put("CODE", task.getBusinessSN());
					map.put("MONEY", task.getBusinessMoney());
					map.put("SUBMITUSER", task.getSubmitUserName());
					map.put("CREATETIME", DateConvertUtil.dateToString(task.getCreateTime()));
				//	map.put("ENDTIME", DateConvertUtil.dateToString(task.getEndTime()));
					map.put("BUISNESSTYPENAME", task.getBusinessName());
					if(null != task.getNextOperators() && !"".equals(task.getNextOperators()))
					{
						map.put("NEXTOPRATORNAME", task.getNextOperators());
					}
					else
					{
						map.put("NEXTOPRATORNAME", "流程已结束 ");
					}
				//	map.put("STATUS", task.getState());
					map.put("ID", task.getBusinessRecordId());
				//	map.put("TASKID", task.getId());
					StringBuffer  bf = new StringBuffer();
					bf.append(task.getUrl());
					bf.append("?");
					bf.append("COMMITERCODE=");
					bf.append(userCode);
					bf.append("&");
					bf.append("id=");
					bf.append(task.getBusinessRecordId());
					map.put("BUSINESSURL", bf.toString());
				//	map.put("PROCESSINSTANCEID", task.getProcessInstanceId());
					list.add(map);
				}
			}
			ApprocalAssistance.commitTransaction();
		//	Map map1 = new HashMap();
			//map1.put("rows", list);
		//map1.put("total", new Long(page.getTotalCount()));
		//	this.getContext().addAttribute("result", map1);
		} catch (Exception je) {
			ApprocalAssistance.rollbackTransaction();
		}
		return list;
	}
	
	private ServiceFactory getServiceFactory() {
		return ServiceFactoryImpl.getServiceFactory();
	}
}
